package com.mytest;


import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Resource {
    private Integer ticket = 30;

    public void getTicket() {
        Lock lock = new ReentrantLock();
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"=>"+ticket--);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }

    public void setTicket(Integer ticket) {
        this.ticket = ticket;
    }
}
